import { _decorator, Color, Component, Sprite } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('PixelItem')
export class PixelItem extends Component {
    pixelNum: number = 1

    start() {
        // 渐显
        // this.setAlphaToZero()
        // this.schedule(this.show, Math.random()*0.01+0.005)
    }

    /** 
     * @zh
     * 逐渐变得不透明。
    */
    show() {
        let color = this.node.getComponent(Sprite).color
        let newAlphaValue = color.a + 5
        this.node.getComponent(Sprite).color = new Color(color.r, color.g, color.b, newAlphaValue)
        
        if (newAlphaValue >= 255) {
            this.unschedule(this.show)
        }
    }

    /** 
     * @zh
     * 一开始要设置图片的alpha值为0，否则刚生成像素块时设置的十六进制颜色就会直接让计时器中的逻辑无效。
    */
    setAlphaToZero() {
        let color = this.node.getComponent(Sprite).color
        this.node.getComponent(Sprite).color = new Color(color.r, color.g, color.b, 0)
    }
}


